﻿/*! jQuery Custom - v1.0 - 2014-04-08*/
/*Haisong Ye (hye@sycamores.indstate.edu)*/

/*include following html section at the end of html file*/
/*<div id="dialog-message" title="Message">
    <p>
        <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;">Message</span>
        <span id="msg_in_dialog"></span>
    </p>
</div>
*/

$(document).ready(function () {
    
    
    
    //fields changed
    var changed = false;
    
    $("input").change(function (event) {
        changed = true;
    });

    $("textarea").change(function (event) {
        changed = true;
    });

    $("a").click(function (event) {
        if (changed && $("#dialog-message").attr("id") == "dialog-message") {
            event.preventDefault();
            var url = $(this).attr("href");
            $('#msg_in_dialog').html("There are unsaved changes. <br/>Do you want to leave this page without saving changes?");
            $("#dialog-message").dialog({
                modal: true,
                buttons: {
                    "Continue": function () {
                        $("body").css("cursor", "progress");
                        window.location.href = url;
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });
        }
    });

    
    
});